/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaylistCellWithArtPanel.java
 *
 * Created on Mar 8, 2009, 2:36:51 PM
 */
package com.bff.slimserver.musicjukebox.ui.components;

import com.bff.bjj.ui.component.BJJPanel;
import com.bff.slimserver.music.exceptions.PlaylistException;
import com.bff.bjj.ui.component.ColorProperties;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.ui.components.favorites.FavoritesAddButton;
import com.bff.bjj.utils.Utils;
import java.awt.Color;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JList;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.musicobjects.SlimGenre;

/**
 *
 * @author Music
 */
public class GenreCellPanel extends javax.swing.JPanel implements GenreCellPanelIface {

    private SlimPlaylist playlist;
    private JList listPlaylist;
    private SlimGenre genre;

    /** Creates new form PlaylistCellWithArtPanel */
    public GenreCellPanel(SlimGenre genre, JList listPlaylist) {
        setGenre(genre);

        this.listPlaylist = listPlaylist;

        try {
            this.playlist = JukeboxProperties.getInstance().getPlaylist();
        } catch (PlaylistException ex) {
            Logger.getLogger(GenreCellPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

        initComponents();

        try {
            lblGenre.setText(genre.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        detailPanel = new javax.swing.JPanel();
        lblGenre = new javax.swing.JLabel();
        jPanel1 = new BJJPanel();
        btnAddFavorite = new FavoritesAddButton(getGenre());
        btnAddFavorite.setText(null);
        btnAdd = new GenreAddButton(getPlaylist(), getGenre());
        btnAdd.setText(null);

        setLayout(new java.awt.BorderLayout());

        lblGenre.setText("jLabel1");
        detailPanel.add(lblGenre);

        add(detailPanel, java.awt.BorderLayout.WEST);

        jPanel1.setLayout(new java.awt.GridBagLayout());
        jPanel1.add(btnAddFavorite, new java.awt.GridBagConstraints());
        jPanel1.add(btnAdd, new java.awt.GridBagConstraints());

        add(jPanel1, java.awt.BorderLayout.EAST);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnAddFavorite;
    private javax.swing.JPanel detailPanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblGenre;
    // End of variables declaration//GEN-END:variables

    public void setEven() {
        setBackground(ColorProperties.LIST_BACKGROUND_EVEN);
    }

    public void setOdd() {
        setBackground(ColorProperties.LIST_BACKGROUND_ODD);
    }

    public void setCurrentPlaying() {
        setForeground(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
        setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
        showAddButton();
    }

    public void setNotSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND);
        hideAddButton();
    }

    @Override
    public void setBackground(Color bg) {
        super.setBackground(bg);
        //detailPanel.setBackground(bg);
        if (detailPanel != null) {
            detailPanel.setBackground(bg);
            jPanel1.setBackground(bg);
        }
    }

    @Override
    public void setForeground(Color fg) {
        super.setForeground(fg);
        if (detailPanel != null) {
            detailPanel.setForeground(fg);
            jPanel1.setForeground(fg);
        }
        setLabelColors(fg);
    }

    private void setLabelColors(Color color) {
        if (lblGenre != null) {
            lblGenre.setForeground(color);
        }
    }

    public void setAddButtonVisible(boolean visible) {
        jPanel1.setVisible(visible);
    }

    public void showAddButton() {
        setAddButtonVisible(true);
    }

    public void hideAddButton() {
        setAddButtonVisible(false);
    }

    @Override
    public Component getPanel() {
        return this;
    }

    public SlimPlaylist getPlaylist() {
        return playlist;
    }

    public void setPlaylist(SlimPlaylist playlist) {
        this.playlist = playlist;
    }

    public void setCurrent() {
        setLabelColors(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setNotCurrent() {
        setLabelColors(ColorProperties.LIST_FOREGROUND_SELECTED);
    }

    @Override
    public void loadThumbnail() {
    }

    /**
     * @return the genre
     */
    private SlimGenre getGenre() {
        return genre;
    }

    /**
     * @param genre the genre to set
     */
    private void setGenre(SlimGenre genre) {
        this.genre = genre;
    }
}
